﻿using GetClient_info;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Vision.AlgBase.InspeAlg
{
    [ServiceData(SeriveName = "OCR识别", Descri = "啥也不检测")]
    public class TempOCRAlg : ToolBase
    {     
        /// <summary>
        /// 黑底白字OR白底黑字
        /// </summary>
        public  bool IsBlackText
        {
            get { return _isBlackText; }
            set { _isBlackText = value; }
        }
        bool _isBlackText = true;
        /// <summary>
        /// 截取的原图
        /// </summary>
        [Browsable(false)]
        public  Bitmap Image
        {
            get { return _image; }
            set { _image = value; }
        }
         Bitmap _image = null;
        /// <summary>
        /// 预处理后的图像
        /// </summary>
        [Browsable(false)]
        public  Bitmap Image2
        {
            get { return _image2; }
            set { _image2 = value; }
        }
         Bitmap _image2 = null;

        protected override bool Excute()
        {
            //测试算法
            string str = GetIntPtr();
            if (str.Contains("OK"))
            {
                //根据句柄获取控件大小
                int x = 0, y = 0, wight = 0, hight = 0;
                OperationWindowProcess.GetWindowRect(ContorIntprt, ref x, ref y, ref wight, ref hight);
                //截图
                OperationWindowProcess.CaptureDesktop(x, y, wight, hight, out _image);

                //图像预处理rgb>>黑白
                if (IsBlackText)
                    _image2 = OperationWindowProcess.PreprocesImage2(_image);
                else
                    _image2 = OperationWindowProcess.PreprocesImage(_image);
                //ocr
                ResultText = OperationWindowProcess.ocr_B(_image2, true);

                ErrLog = "";
                return true;
              
            }
            else
            {
                ErrLog = str;
                return false;

            }

        }
    }
}
